package cvsexample7;

public class CallStackExample {
	
	/* private global variable */
	private static int numMethodCalls = 0;
	
	/* methodA to call methodB and increment/decrement the global variable */
	public static void methodA() {
		System.out.println("Enter methodA: Number of method calls = " + (++numMethodCalls));
		methodB();
		System.out.println("Exit methodA: Number of method calls = " + numMethodCalls--);
	}
	
	/* methodB to call methodC and increment/decrement the global variable */
	public static void methodB() {
		System.out.println("Enter methodB: Number of method calls = " + (++numMethodCalls));
		methodC();
		System.out.println("Exit methodB: Number of method calls = " + numMethodCalls--);
	}
	
	/* methodC to call methodD and increment/decrement the global variable */
	public static void methodC() {
		System.out.println("Enter methodC: Number of method calls = " + (++numMethodCalls));
		methodD();
		System.out.println("Exit methodC: Number of method calls = " + numMethodCalls--);
	}
	
	/* methodD to increment/decrement the global variable */
	public static void methodD() {
		System.out.println("Enter methodD: Number of method calls = " + (++numMethodCalls));
		System.out.println("Exit methodD: Number of method calls = " + numMethodCalls--);
	}

	public static void main(String[] args) {
		
		/* Output a start message to the console */
		System.out.println("Example 7 - Call Stack started");
		
		System.out.println("Enter main method");
		methodA();
		System.out.println("Exit main method");
		
		/* Output a completed message to the console */
		System.out.println("Example 7 - Call Stack completed");
	}
}
